package com.kvw.filesystem;

import com.kvw.filesystem.core.minio.MinioStorage;
import com.kvw.filesystem.model.FileObject;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-07-17
 * Time: 23:12
 */
public class FsTest {
    public static void main(String[] args) throws Exception {
        String filePath = "D:\\React Native入门与实战.pdf";
        String bucket = "kvw";
        MinioStorage minioStorage = new MinioStorage();
        /*if (!minioStorage.bucketExists(bucket)) {
            minioStorage.makeBucket(bucket);
        }*/

        FileInputStream inputStream = new FileInputStream(filePath);
        FileObject fileObject = FileObject.builder()
                .fileName("React Native入门与实战.pdf")
                .bucket(bucket)
                .dataSource(inputStream)
                .build();

       String fileId = minioStorage.upload(fileObject);
        System.out.println(fileId);
        /*InputStream bis = minioStorage.download(fileObject);
        File file = new File("laicmjwkqo2.jpg");
        file.createNewFile();
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        byte[] bytes = new byte[4096];
        int len;
        while ((len = bis.read(bytes)) != -1) {
            fileOutputStream.write(bytes, 0, len);
        }
        bis.close();
        fileOutputStream.flush();
        fileOutputStream.close();*/
        /*FileObject fileObject = FileObject.builder()
                .bucket(bucket)
                .fileId("b7cd4272f40842f695b5db607c27a98d_laicmjwkqo2.jpg")
                .build();
        System.out.println(minioStorage.delete(fileObject));*/
    }
}
